﻿using Sage.DownloadLite.Models;

namespace Sage.DownloadLite.Interfaces
{
    /// <summary>
    /// HTTP服务接口
    /// </summary>
    public interface IHttpService
    {
        /// <summary>
        /// 设置超时时间
        /// </summary>
        /// <param name="timeout">超时时间</param>
        void SetTimeout(TimeSpan timeout);

        /// <summary>
        /// 设置用户代理字符串
        /// </summary>
        /// <param name="userAgent">用户代理字符串</param>
        void SetUserAgent(string userAgent);

        /// <summary>
        /// 异步下载文件
        /// </summary>
        /// <param name="taskInfo">任务信息</param>
        /// <param name="progress">进度回调</param>
        /// <param name="progressInterval">进度更新间隔（百分比）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>任务结果</returns>
        Task<TaskResult> DownloadFileAsync(TaskInfo taskInfo,
            IProgress<SingleDownloadProgress>? progress = null,
            double progressInterval = 1.0,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 检查文件是否存在
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns>是否存在</returns>
        bool FileExists(string filePath);

        /// <summary>
        /// 释放资源
        /// </summary>
        void Dispose();
    }
}
